package com.freewater.library.common.domain;

import java.util.ArrayList;
import java.util.List;

public abstract class BaseAggregateRoot extends BaseEntity {

    private List<DomainEvent> events;

    protected BaseAggregateRoot() {
        this.clearEvents();
    }

    public void raiseEvent(DomainEvent event) {
        this.getEvents().add(event);
    }

    public void clearEvents() {
        this.getEvents().clear();
    }

    public List<DomainEvent> getEvents() {
        if (this.events == null) {
            this.events = new ArrayList<>();
        }
        return this.events;
    }
}
